package com.example.smartclassroom.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartclassroom.entity.form.LoginForm;
import com.example.smartclassroom.entity.Teacher;
import com.example.smartclassroom.mapper.TeacherMapper;
import com.example.smartclassroom.service.TeacherService;
import com.example.smartclassroom.util.JsonDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherSeiveceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;
    //老师登录
    public Teacher login(LoginForm loginForm) {
        Teacher login = teacherMapper.login(loginForm);
        if (login != null){
            return login;
        }
        throw  new RuntimeException("账号密码错误");
    }

    //老师注册
    public Integer register(LoginForm loginForm) {
        return teacherMapper.insert(loginForm);
    }

    //编辑老师信息
    public JsonDate update(Teacher teacher) {
        JsonDate date=new JsonDate();
        Integer rows=teacherMapper.update(teacher);
        if (rows>0){
            date.setCode(0);
            date.setMsg("success");
        }else {
            date.setCode(1);
            date.setMsg("fail");
        }
        return date;
    }
    /**
     * 查询所有老师姓名
     */
    public JsonDate queryAllTeacherName() {
        JsonDate date=new JsonDate();
        date.setData(teacherMapper.queryAllTeacherName());
        return date;
    }
}
